package yunhe.service.impl;

import org.apache.ibatis.session.SqlSession;
import yunhe.dao.NewsDao;
import yunhe.entity.NewsInfo;
import yunhe.service.NewsServers;
import yunhe.util.SqlSessionFactoryUtil;

import java.util.List;

public class NewsServersImpl implements NewsServers {

	private static SqlSession sse=SqlSessionFactoryUtil.getSqlSession();
	private static NewsDao nsd=sse.getMapper(NewsDao.class);
	
	public List<NewsInfo> getPageBy(int pageSige, int currentPage) {

		return nsd.getPageBy(pageSige, currentPage);
		
	}

	public int getRowNum() {

		return nsd.getRowNum();
	}

	public int addNews(NewsInfo ni) {

		return nsd.addNews(ni);
	}

	public int updateNews(NewsInfo ni) {

		return nsd.updateNews(ni);
	}

	public String seach(String text) {
		String s = "";
		if (!"".equals(text)) {
			List<NewsInfo> lni = nsd.seachBy(text);

			for (NewsInfo ni : lni) {
				s += ni.getTitle() + "<>";
			}
			if (!"".equals(s)) {
				s = s.substring(0, s.length() - 2);
			}
		}
		return s;
	}

}
